package com.orange.example.controller;

import com.orange.common.autoconfig.template.OssTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @Description: 云服务AutoConfig模块的测试单元
 */
@RestController
public class AutoConfigController {

    /**
     * @Description: 比如我需要在这里使用到阿里云的oss服务
     * 1先引入AutoConfig模块
     * 2注入oss对象---一定要配置你的阿里云账号，不然注入后，使用方法时会报错
     */
    @Autowired
    private OssTemplate ossTemplate;

    /**
     * @Description: 测试上传文件到oss(成功)
     */
    @GetMapping("auto/oss")
    public String test() throws FileNotFoundException {
        //先获取到图片数据
        FileInputStream fileInputStream = new FileInputStream(new File("/Users/orange/Documents/W_日常文件/截图/yeshengjun.png"));
        ossTemplate.upload("yeshengjun.png",fileInputStream);
        return "success";
    }

}
